package com.audi.utils;

import java.util.ArrayList;

import android.content.Context;

import com.audi.R;

public class DeviceHelper {

	public static int getProperty(int typeIndex, int statusValue) {
		int resource = 0;
		switch (typeIndex) {
		case 0: // ONOFF_PLUG
		case 1: // ONOFF_SWITCH
		case 2: // ONOFF_LIGHTING
		case 3: // ONFF_DOORLOCK
			if (statusValue == 1) {
				resource = R.drawable.btn_device_control_onoff_on;
			} else {
				resource = R.drawable.btn_device_control_onoff_off;
			}
			break;
		case 4: // WARNING_CO
		case 5: // WARNING_CO2
		case 6: // WARNING_GAS
		case 7: // WARNING_FIRE
		case 8: // WARNING_SMOKE
		case 9: // WARNING_GLASS
		case 10: // WARNING_ALARM
			if (statusValue == 1) {
				resource = R.drawable.btn_device_control_warning_yes;
			} else {
				resource = R.drawable.btn_device_control_warning_no;
			}
			break;
		case 11: // STATUS_TEMPERATURE
			if (statusValue < 18) {
				resource = R.color.temperature_blue;
			} else if (statusValue > 25) {
				resource = R.color.temperature_orange;
			} else {
				resource = R.color.temperature_green;
			}
			break;
		case 12: // STATUS_HUMIDITY
			if (statusValue < 64) {
				resource = R.color.humidity_blue;
			} else if (statusValue > 77) {
				resource = R.color.humidity_orange;
			} else {
				resource = R.color.humidity_green;
			}
			break;
		case 13: // STATUS_DOOR
		case 14: // STATUS_WINDOW
			if (statusValue == 1) {
				resource = R.drawable.btn_device_control_status_open;
			} else {
				resource = R.drawable.btn_device_control_status_close;
			}
			break;
		case 15: // STATUS_MOTION
			if (statusValue == 1) {
				resource = R.drawable.btn_device_control_status_detect;
			} else {
				resource = R.drawable.btn_device_control_status_none;
			}
			break;
		default:
			break;
		}
		return resource;
	}

	public static String getName(Context context, int typeIndex) {
		String name = null;
		switch (typeIndex) {
		case 0: // ONOFF_PLUG
			name = context.getResources().getString(R.string.device_name_plug);
			break;
		case 1: // ONOFF_SWITCH
			name = context.getResources()
					.getString(R.string.device_name_switch);
			break;
		case 2: // ONOFF_LIGHTING
			name = context.getResources().getString(
					R.string.device_name_lighting);
			break;
		case 3: // ONFF_DOORLOCK
			name = context.getResources().getString(
					R.string.device_name_doorlock);
			break;
		case 4: // WARNING_CO
			name = context.getResources().getString(R.string.device_name_co);
			break;
		case 5: // WARNING_CO2
			name = context.getResources().getString(R.string.device_name_co2);
			break;
		case 6: // WARNING_GAS
			name = context.getResources().getString(R.string.device_name_gas);
			break;
		case 7: // WARNING_FIRE
			name = context.getResources().getString(R.string.device_name_fire);
			break;
		case 8: // WARNING_SMOKE
			name = context.getResources().getString(R.string.device_name_smoke);
			break;
		case 9: // WARNING_GLASS
			name = context.getResources().getString(R.string.device_name_glass);
			break;
		case 10: // WARNING_ALARM
			name = context.getResources().getString(R.string.device_name_alarm);
			break;
		case 11: // STATUS_TEMPERATURE
			name = context.getResources().getString(
					R.string.device_name_temperature);
			break;
		case 12: // STATUS_HUMIDITY
			name = context.getResources().getString(
					R.string.device_name_humidity);
			break;
		case 13: // STATUS_DOOR
			name = context.getResources().getString(R.string.device_name_door);
			break;
		case 14: // STATUS_WINDOW
			name = context.getResources()
					.getString(R.string.device_name_window);
			break;
		case 15: // STATUS_MOTION
			name = context.getResources()
					.getString(R.string.device_name_motion);
			break;
		default:
			break;
		}
		return name;
	}

	public static int getGroupType(int typeIndex) {
		int returnType = 0;
		switch (typeIndex) {
		case 0: // ONOFF_PLUG
		case 1: // ONOFF_SWITCH
		case 2: // ONOFF_LIGHTING
		case 3: // ONFF_DOORLOCK
			return Constants.DEVICE_GROUP_TYPE.ONOFF.ordinal();
		case 4: // WARNING_CO
		case 5: // WARNING_CO2
		case 6: // WARNING_GAS
		case 7: // WARNING_FIRE
		case 8: // WARNING_SMOKE
		case 9: // WARNING_GLASS
		case 10: // WARNING_ALARM
			return Constants.DEVICE_GROUP_TYPE.WARNING.ordinal();
		case 11: // STATUS_TEMPERATURE
		case 12: // STATUS_HUMIDITY
		case 13: // STATUS_DOOR
		case 14: // STATUS_WINDOW
		case 15: // STATUS_MOTION
			return Constants.DEVICE_GROUP_TYPE.STATUS.ordinal();
		default:
			break;
		}
		return returnType;
	}
	public static String getGroupName(int typeIndex) {
		
		switch (typeIndex) {
		case 0: // ONOFF_PLUG
		case 1: // ONOFF_SWITCH
		case 2: // ONOFF_LIGHTING
		case 3: // ONFF_DOORLOCK
			return "On/Off";
		case 4: // WARNING_CO
		case 5: // WARNING_CO2
		case 6: // WARNING_GAS
		case 7: // WARNING_FIRE
		case 8: // WARNING_SMOKE
		case 9: // WARNING_GLASS
		case 10: // WARNING_ALARM
			return "Warning";
		case 11: // STATUS_TEMPERATURE
		case 12: // STATUS_HUMIDITY
		case 13: // STATUS_DOOR
		case 14: // STATUS_WINDOW
		case 15: // STATUS_MOTION
			return "Status";
		default:
			break;
		}
		return "";
	}
	public static ArrayList<Integer> getListType(int groupTypeIndex) {
		ArrayList<Integer> returnData = new ArrayList<Integer>();
		switch (groupTypeIndex) {
		case 0:
			returnData.add(0);
			returnData.add(1);
			returnData.add(2);
			returnData.add(3);
			break;
		case 1:
			returnData.add(4);
			returnData.add(5);
			returnData.add(6);
			returnData.add(7);
			returnData.add(8);
			returnData.add(9);
			returnData.add(10);
			break;
		case 2:
			returnData.add(11);
			returnData.add(12);
			returnData.add(13);
			returnData.add(14);
			returnData.add(15);
			break;
		}
		return returnData;
	}

	public static int getControlType(int typeIndex) {
		int returnType = 0;
		switch (typeIndex) {
		case 0: // ONOFF_PLUG
		case 1: // ONOFF_SWITCH
		case 2: // ONOFF_LIGHTING
		case 3: // ONFF_DOORLOCK
		case 4: // WARNING_CO
		case 5: // WARNING_CO2
		case 6: // WARNING_GAS
		case 7: // WARNING_FIRE
		case 8: // WARNING_SMOKE
		case 9: // WARNING_GLASS
		case 10: // WARNING_ALARM
		case 13: // STATUS_DOOR
		case 14: // STATUS_WINDOW
		case 15: // STATUS_MOTION
			returnType = 1;
			break;
		case 11: // STATUS_TEMPERATURE
		case 12: // STATUS_HUMIDITY
			returnType = 2;
			break;
		default:
			break;
		}
		return returnType;
	}

	public static boolean hasUnit(int typeIndex) {
		boolean flag = false;
		switch (typeIndex) {
		case 11: // STATUS_TEMPERATURE
			flag = true;
			break;
		default:
			break;
		}
		return flag;
	}

	public static int getUnit(int typeIndex) {
		int resource = 0;
		switch (typeIndex) {
		case 11: // STATUS_TEMPERATURE
			resource = R.string.unit_temperature;
			break;
		default:
			break;
		}
		return resource;
	}
}
